/*
Copyright (c) 2007, Arturo José Guédez Romero

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of Cultusoft nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package com.cultusoft.groovin.script;

import java.util.Date
import com.cultusoft.groovin.log.GroovinLogger

class GroovinProperties {
    
    public static final String trackChanges = "trackChanges"
    public static final String debug  = "debug"
    public static final String forceTests  = "forceTests"
    public static final String forcePackaging  = "forcePackaging"
    public static final String forceCompile  = "forceCompile"
    public static final String forceClean  = "forceClean"

    static def args = [] as List
        
    static def groovinProperties = [trackChanges:true, 
                                    debug:false, 
                                    forceTests:false, 
                                    forcePackaging:false, 
                                    forceCompile:false,
                                    forceClean:false]
    
    static def logger = new GroovinLogger(GroovinProperties.class)
    
    public static void setProperty(def name, def value) {
        if (groovinProperties[name] == null) {
           logger.log("Invalid property setting: $name")
           printKnownProperties()
           throw new Exception("Invalid property setting: $name")
        }
        def booleanValue = false;
        if ("true" == value) {
            booleanValue = true
        } else if ("false" == value) {
            booleanValue = false
        } else {
            throw new Exception("Invalid value \"$value\" for property \"$name\". Boolean value expected.");
        }
        groovinProperties.put(name, booleanValue)
    }
    
    private static void printKnownProperties() {
        logger.log("Valid Groovin properties are:")
        groovinProperties.each { logger.log( it.key + "=" + it.value)} 
    }
    
    public static boolean isEnabled(def name) {
        if (groovinProperties[name] != null) { 
            return groovinProperties[name]
        } else {
            throw new Exception("Unknown property " + name)
        }
    }
    
}
